package com.ykh.spring;

import com.alibaba.druid.pool.DruidDataSource;
import com.ykh.spring.pojo.Clazz;
import com.ykh.spring.pojo.Student;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-08-21
 * Time: 17:40
 */
public class test {
    @Test
    public void IOCTest() {
        ApplicationContext ioc = new ClassPathXmlApplicationContext("spring-ioc.xml");
        Student studentOne = (Student) ioc.getBean("studentOne");
        System.out.println(studentOne);

        Student studentTwo = ioc.getBean("studentTwo",Student.class);
        System.out.println(studentTwo);

//        System.out.println("========================================");
//        Clazz clazzOne = (Clazz) ioc.getBean("clazzOne",Clazz.class);
//        System.out.println(clazzOne);

    }

    @Test
    public void datasourceTest() throws SQLException {
        ApplicationContext ioc = new ClassPathXmlApplicationContext("spring-datasources.xml");
        DruidDataSource dataSource = ioc.getBean("druidDataSource", DruidDataSource.class);
        System.out.println(dataSource.getConnection());

    }
}
